package com.dzsw.mustache;

import com.github.mustachejava.DefaultMustacheFactory;
import com.github.mustachejava.Mustache;
import com.github.mustachejava.MustacheFactory;

import java.io.IOException;
import java.io.StringReader;
import java.io.StringWriter;

/**
 * 基础的模板引擎示例
 */
public class BasicExample {

    public static void main(String[] args) throws IOException {
        // 创建 Mustache 工厂
        MustacheFactory mf = new DefaultMustacheFactory();
        // 编译一个简单的模板
        Mustache mustache = mf.compile(new StringReader("Hello, {{name}}!"), "");
        // 用于写入模板输出的 StringWriter
        StringWriter writer = new StringWriter();
        // 执行模板与上下文
        mustache.execute(writer, new Object() {
            String name = "World"; // 数据上下文
        }).flush();
        // 输出结果
        System.out.println(writer.toString()); // 输出 Hello, World!
    }
}
